/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.model;

import com.admin.controller.EventCommentManagerRemote;
import com.common.json.EventManagerJson;
import com.entities.EventComment;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author Tuan Long
 */
public class EventCommentModel {
    EventCommentManagerRemote eventCommentManager;

    
    public EventCommentModel() {
        eventCommentManager = lookupEventCommentManagerRemote();
    }

    public List<EventComment> readEventComments() {
        List<EventComment> list = new ArrayList<EventComment>();
        //Lay du lieu tu goi ejb gui ve
        List<String> listJson = eventCommentManager.readEventComments();
        for (String json : listJson) {
            EventComment ec = EventManagerJson.convertJsonStringToEventCommentForRedEventComments(json);
            list.add(ec);
        }
        return list;
    }

    private EventCommentManagerRemote lookupEventCommentManagerRemote() {
        try {
            Context c = new InitialContext();
            return (EventCommentManagerRemote) c.lookup("java:global/BluePumpkinEJB/EventCommentManager!com.admin.controller.EventCommentManagerRemote");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }

}
